package com.play.game.mymvp;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

/**
 * Created by 聪明一只哈 on 2018/4/10.
 * Time: 2018/4/10  9:58
 */

public class MyAdapter extends BaseAdapter {
    private Context context;
    private List<Bean.DataBean> data;

    public MyAdapter(Context context, List<Bean.DataBean> data) {

        this.context = context;
        this.data = data;
    }

    @Override
    public int getCount() {
        return data==null?0:data.size();
    }

    @Override
    public Object getItem(int i) {
        return data.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View convertview, ViewGroup viewGroup) {
        ViewHolder vh;
        if(convertview==null){
            vh=new ViewHolder();
            convertview=View.inflate(viewGroup.getContext(),R.layout.item,null);
            vh.tv1=convertview.findViewById(R.id.tv1);
            vh.tv2=convertview.findViewById(R.id.tv2);

            convertview.setTag(vh);
        }else{
            vh= (ViewHolder) convertview.getTag();
        }

        vh.tv1.setText(data.get(i).getTime());
        vh.tv2.setText(data.get(i).getContext());



        return convertview;
    }

    static class ViewHolder{
        TextView tv1,tv2;
    }
}
